package com.limh.keepalive

import android.content.ActivityNotFoundException
import android.content.ComponentName
import android.content.Intent
import com.limh.keepalive.core.BaseActivity
import com.limh.keepalive.databinding.ActivityMainBinding

class MainActivity : BaseActivity<ActivityMainBinding>() {

    override fun initViews() {

    }

    override fun initDatas() {
        openNotifyListener()
    }

    /**
     * 打开通知使用
     */
    private fun openNotifyListener(){
        try {
            val intent = Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS")
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            startActivity(intent)
        } catch (e: ActivityNotFoundException) {
            try {
                val intent = Intent()
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                val cn = ComponentName("com.android.settings", "com.android.settings.Settings\$NotificationAccessSettingsActivity")
                intent.component = cn
                intent.putExtra(":settings:show_fragment", "NotificationAccessSettings")
                startActivity(intent)
            } catch (e: Exception) {
                e.printStackTrace()
            }
        }
    }

    /**
     * 初始化worker
     */
    private fun openWorker(){

    }
}